Fix encryption when bad response exception#110
Open
DrArmansky wants to merge 3 commits intohyperwallet:masterfrom
Open
Fix encryption when bad response exception#110DrArmansky wants to merge 3 commits intohyperwallet:masterfrom
DrArmansky wants to merge 3 commits intohyperwallet:masterfrom
Conversation
Collaborator
There was a problem hiding this comment.
Great catch @DrArmansky thanks for your contribution.
src/Hyperwallet/Util/ApiClient.php
Outdated
| throw new HyperwalletApiException($errorResponse, $e); | ||
| } catch (BadResponseException $e) { | ||
| $body = \GuzzleHttp\json_decode($e->getResponse()->getBody(), true); | ||
| $body = $this->isEncrypted ? \GuzzleHttp\json_decode(\GuzzleHttp\json_encode($this->encryption->decrypt($e->getResponse()->getBody())), true) : |
Collaborator
There was a problem hiding this comment.
-
Could you split each function call into single execution that will improve readability. or few free to introduce new function to handle the JSON decode.
-
Can you also introduce a Unit test to validate this use case as well.
Collaborator
There was a problem hiding this comment.
Ohh, I checked the whole method and I see that is the same approach on line 175
php-sdk/src/Hyperwallet/Util/ApiClient.php
Line 175 in a8cccc7
- Could you introduce a function to handle the body decoding ? and reuse it on line 175 as well
Author
There was a problem hiding this comment.
@grmeyer-hw-dev made the decryption of the response a separate function and unit test added. Please check.
000ff48 to
79a8f95
Compare
1 similar comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If encryption is used and BadResponseException was happened then when trying to extract the response body, an error occurs:
json_decode error: Syntax error, which makes it impossible to see the real cause of the error. In this pull request, I'm fixing it.